package com.century.sjt.activity.Pay;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.century.sjt.R;
import com.century.sjt.SjtHelper;
import com.century.sjt.activity.BaseActivity;
import com.century.sjt.activity.QRRecordCodeScanActivity;
import com.century.sjt.adapter.MerchantListAdapter;
import com.century.sjt.entity.Merchant;
import com.century.sjt.util.Constant;
import com.century.sjt.util.TipUtil;
import com.century.sjt.widget.TitleBar.SjtTitleBar;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMContactManager;
import com.century.sjt.EMChat.widget.EaseAlertDialog;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商家列表
 */
public class MerchantActivity extends BaseActivity {
    private SjtTitleBar titleBar;
    private EditText aQueryText;

    private String payType;
    private List<Merchant> mDatalist;
    private ListView listStores;
    private MerchantListAdapter adapter;

    private String pageSize="10";
    private int iCurrPage=1;
    private SwipeRefreshLayout mSwipeLayout;        //刷新组件
    private Handler mHandler;
    private Boolean isDataChangeOk=true;

    private ProgressDialog progressDialog;
    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sjt_merchant_pay_activity);
        mContext = this;
        Intent intent = getIntent();
        String aType=null;

        aType = intent.getStringExtra("payType");
        if (aType==null){
            payType="1";
        }else {
            payType = aType;
        }

        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        adapter.notifyDataSetChanged();
                        TipUtil.closeProgressDialog();
                        mSwipeLayout.setRefreshing(false);
                        break;
                    case 2:
                        isDataChangeOk=true;
                        mDatalist.clear();
                        iCurrPage = 1;
                        getRecords();
                        break;
                    case 3:
                        if(isDataChangeOk) {
                            mSwipeLayout.setRefreshing(true);
                            iCurrPage++;
                            getRecords();
                        }
                        break;
                    case 4:
                        mDatalist.clear();
                        getRecordsTo();
                        break;

                }
            }
        };

        initView();

    }
    @Override
    protected void initView() {
        aQueryText=(EditText)findViewById(R.id.query);
        mDatalist = new ArrayList<>();
        titleBar = (SjtTitleBar) findViewById(R.id.title_bar);
        titleBar.setTitle(getResources().getString(R.string.tab_payok));
        listStores = (ListView) findViewById(R.id.list_mp_stores);
        adapter = new MerchantListAdapter(MerchantActivity.this,mDatalist,mQueue);
        listStores.setAdapter(adapter);
//        listStores.setOnScrollListener(new AbsListView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(AbsListView absListView, int i) {
//                // 当不滚动时
//                if (i == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
//                    // 判断是否滚动到底部
//                    if (absListView.getLastVisiblePosition() == absListView.getCount() - 1) {
//                        //加载更多功能的代码
//                        Message msg = new Message();
//                        msg.what = 3;
//                        mHandler.sendMessage(msg);
//                    }
//                }
//            }
//
//            @Override
//            public void onScroll(AbsListView absListView, int i, int i1, int i2) {
//
//            }
//        });
        //刷新组件
        mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.activity_list_refesh);
        //刷新组件
        mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Message msg = new Message();
                msg.what = 2;
                mHandler.sendMessage(msg);
            }
        });
        mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
                android.R.color.holo_orange_light, android.R.color.holo_red_light);


//        titleBar.setRightIconResourc(getResources().getString(R.string.icon_scan_it));
//        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent2 = new Intent();
//                intent2.setClass(MerchantActivity.this, QRRecordCodeScanActivity.class);
//                intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                startActivityForResult(intent2, Constant.SCANNIN_GREQUEST_CODE);
//            }
//        });
        listStores.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.setClass(MerchantActivity.this, MerchantItemActivity.class);
                Bundle mBundle = new Bundle();
                mBundle.putSerializable("Merchant", mDatalist.get(i));
                intent.putExtras(mBundle);
                intent.putExtra("payType", payType);
                startActivity(intent);
            }
        });

        listStores.setOnScrollListener(new AbsListView.OnScrollListener(){
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i)
            {
                switch (i) {
                    // 当不滚动时
                    case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
                        // 判断滚动到底部
                        mSwipeLayout.setEnabled(true);
                        if (listStores.getLastVisiblePosition() == (listStores.getCount() - 1)) {
                            //加载更多功能的代码
                            Message msg = new Message();
                            msg.what = 3;
                            mHandler.sendMessage(msg);
                        }
                        // 判断滚动到顶部
                        if(listStores.getFirstVisiblePosition() == 0){
//                            Message msg = new Message();
//                            msg.what = 2;
//                            mHandler.sendMessage(msg);
                        }
                        break;
                    case  AbsListView.OnScrollListener.SCROLL_STATE_FLING:
//                        Log.v("开始滚动：SCROLL_STATE_FLING");
                        mSwipeLayout.setEnabled(false);
                        break;
                    case  AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
//                        Log.v("正在滚动：SCROLL_STATE_TOUCH_SCROLL");
                        mSwipeLayout.setEnabled(false);
                        break;
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount)
            {
                View firstView = absListView.getChildAt(firstVisibleItem);
                if (firstVisibleItem == 0 && (firstView == null || firstView.getTop() == 0))
                    mSwipeLayout.setEnabled(true);
                else
                    mSwipeLayout.setEnabled(false);
//
//                if (firstVisibleItem + visibleItemCount == totalItemCount && !isDataChangeOk) {
//                    isDataChangeOk = true;
//                } else
//                    isDataChangeOk = false;

            }
        });
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        //软键盘设置
        aQueryText.setOnEditorActionListener(new TextView.OnEditorActionListener(){
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                 /*判断是否是“GO”键*/
                if(actionId == EditorInfo.IME_ACTION_SEARCH){
                    /*隐藏软键盘*/
                    InputMethodManager imm = (InputMethodManager) v
                            .getContext().getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                    if (imm.isActive()) {
                        imm.hideSoftInputFromWindow(
                                v.getApplicationWindowToken(), 0);
                    }

//                    edittext.setText("success");
//                    webview.loadUrl(URL);
                    Message msg = new Message();
                    msg.what = 4;
                    mHandler.sendMessage(msg);
                    return true;
                }
                return false;
            }
        });
        aQueryText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                Message msg = new Message();
                msg.what = 4;
                mHandler.sendMessage(msg);
            }
        });

//        getRecords();
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onResume() {
        Message msg = new Message();
        msg.what = 2;
        mHandler.sendMessage(msg);
        super.onResume();
    }


    /**
     * 扫描返回数据
     * @param requestCode
     * @param resultCode
     * @param data
     */
    public void qrRecordCodeResult(int requestCode, int resultCode, Intent data){
        switch (requestCode) {
            case com.century.sjt.util.Constant.SCANNIN_GREQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    Bundle bundle = data.getExtras();
                    Log.e("weixin", bundle.getString("result").toString());
//                    TipUtil.showToast(bundle.getString("result").toString(), MerchantActivity.this, 1);
                    String result = bundle.getString("result");
                    //判断返回字符串数据是打开网页还是加好友
                    if(result.indexOf(com.century.sjt.util.Constant.QRRECORD_ADDFRIEND)>=0) {
                        //判断“：”前后的字符串
                        int i = result.indexOf(':');
//                  int x = mQRCordId.indexOf(':',i+1);
                        String option = result.substring(0, i);
                        String friendId = result.substring(i + 1);
                        switch (option) {
                            case com.century.sjt.util.Constant.QRRECORD_ADDFRIEND:
                                qrAddfrind(friendId);
                                break;
                            default:
                                break;
                        }
                    }else if(result.indexOf(com.century.sjt.util.Constant.QRRECORD_SHOP_ID)>=0) {//扫描商家二维码
//                        商家身份暂不支持支付
                        String isShop = getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE).getString("isShop", "");
                        if("0".equals(isShop)) {
                            //判断“：”前后的字符串
                            int i = result.indexOf(':');
//                          int x = mQRCordId.indexOf(':',i+1);
                            String option = result.substring(0, i);
                            String shopId = result.substring(i + 1);
                            switch (option) {
                                case com.century.sjt.util.Constant.QRRECORD_SHOP_ID:
                                    shopDetail(shopId);
                                    break;
                                default:
                                    break;
                            }
                        }else {
                            TipUtil.showToast(getResources().getString(R.string.error_is_shop), MerchantActivity.this, 1);
                        }
                    }else if(result.indexOf(com.century.sjt.util.Constant.QRRECORD_HTTP)>=0) {
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(result));
                        startActivity(intent);
                    }else{
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse("https://www.baidu.com/s?wd=" + result));
                        startActivity(intent);
                    }

//                    mTextView.setText(bundle.getString("result"));
//                    mImageView.setImageBitmap((Bitmap) data.getParcelableExtra("bitmap"));
                }
                break;

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        qrRecordCodeResult(requestCode,resultCode,data);
    }

    /**
     * 添加好友
     * @param addfriendId
     */
    private void qrAddfrind(final String addfriendId) {

        if(EMChatManager.getInstance().getCurrentUser().equals(addfriendId)){
            new EaseAlertDialog(MerchantActivity.this, R.string.not_add_myself).show();
            return;
        }

        if(SjtHelper.getInstance().getContactList().containsKey(addfriendId)){
            //提示已在好友列表中(在黑名单列表里)，无需添加
//            if(EMContactManager.getInstance().getBlackListUsernames().contains(addfriendId)){
//                new EaseAlertDialog(MerchantActivity.this, R.string.user_already_in_contactlist).show();
//                return;
//            }
            new EaseAlertDialog(MerchantActivity.this, R.string.This_user_is_already_your_friend).show();
            return;
        }

        progressDialog = new ProgressDialog(MerchantActivity.this);
        String stri = getResources().getString(R.string.Is_sending_a_request);
        progressDialog.setMessage(stri);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();

        new Thread(new Runnable() {
            public void run() {

                try {
                    //demo写死了个reason，实际应该让用户手动填入
                    String s = getResources().getString(R.string.Add_a_friend);
                    EMContactManager.getInstance().addContact(addfriendId, s);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            progressDialog.dismiss();
                            String s1 = getResources().getString(R.string.send_successful);
                            TipUtil.showToast(s1, MerchantActivity.this, 1);
//                            Toast.makeText(getApplicationContext(), s1, 1).show();
                        }
                    });
                } catch (final Exception e) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            progressDialog.dismiss();
                            String s2 = getResources().getString(R.string.Request_add_buddy_failure);
                            TipUtil.showToast(s2 + e.getMessage(), MerchantActivity.this, 1);
//                            Toast.makeText(getApplicationContext(), s2 + e.getMessage(), 1).show();
                        }
                    });
                }
            }
        }).start();

    }



    /**
     * 获取商店详情
     * @param shopId
     */
    private void shopDetail(final String shopId) {
        TipUtil.openProgressDialog(com.century.sjt.util.Constant.APPLICATION_NAME, getResources().getString(R.string.error_please_waitting), MerchantActivity.this);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, com.century.sjt.util.Constant.ShopDetail, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.closeProgressDialog();
                    TipUtil.log("接口返回成功", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("407")){
                        TipUtil.showAppayRes(mContext);
                    }
                    if (code.equals("200")) {//成功
                        JSONObject aData = res.getJSONObject("data");
                        Merchant merchant = new Merchant();
                        merchant.setShopId(aData.getString("shopId"));
                        merchant.setShopName(aData.getString("shopName"));
//                            Log.e("name",aData.getString("shopName"));
                        merchant.setLogo(aData.getString("logo"));
                        merchant.setDiscount(aData.getString("discount"));
                        merchant.setAddress(aData.getString("address"));
                        merchant.setTelephone(aData.getString("telephone"));
                        merchant.setTelephoneOne(aData.getString("telephoneOne"));
                        merchant.setMobile(aData.getString("mobile"));
                        merchant.setDesc(aData.getString("desc"));
                        merchant.setCity(aData.getString("city"));
                        merchant.setImage(aData.getString("image"));
                        merchant.setUserId(aData.getString("userId"));
                        merchant.setLastTopic(aData.getString("lastTopic"));
                        merchant.setNewGoods(aData.getString("newGoods"));
                        merchant.setLevel(aData.getInt("level"));
                        Intent intent = new Intent();
                        intent.setClass(MerchantActivity.this, MerchantItemActivity.class);
                        Bundle mBundle = new Bundle();
                        mBundle.putSerializable("Merchant", merchant);
                        intent.putExtras(mBundle);
                        intent.putExtra("shopId", shopId);
                        intent.putExtra("payType","2");
                        startActivity(intent);
                    } else {//失败
                        TipUtil.showToast(message, MerchantActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service),MerchantActivity.this, 1);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), MerchantActivity.this, 1);
                TipUtil.closeProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
//                SharedPreferences mainSharedPreferences =getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
//                String userId = mainSharedPreferences.getString("userId", "");
//                map.put("loginId", userId);
                map.put("shopId",shopId);
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences =getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }

    private void getRecords(){
//        TipUtil.openProgressDialog(Constant.APPLICATION_NAME, getResources().getString(R.string.please_waitting), MerchantActivity.this);
        isDataChangeOk=false;
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.GetMerchantList, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    isDataChangeOk=true;
                    TipUtil.closeProgressDialog();
                    TipUtil.log("商家列表", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功
                        JSONArray data = res.getJSONArray("data");
//                        mDatalist.clear();
                        for (int i = 0; i < data.length(); i++) {
                            JSONObject aData = (JSONObject) data.get(i);
                            Merchant merchant = new Merchant();
                            merchant.setUserId(aData.getString("userId"));
                            merchant.setShopId(aData.getString("shopId"));
                            merchant.setShopName(aData.getString("shopName"));
//                            Log.e("name",aData.getString("shopName"));
                            merchant.setLogo(aData.getString("logo"));
                            merchant.setDiscount(aData.getString("discount"));
                            merchant.setAddress(aData.getString("address"));
                            merchant.setTelephone(aData.getString("telephone"));
                            merchant.setTelephoneOne(aData.getString("telephoneOne"));
                            merchant.setMobile(aData.getString("mobile"));
                            merchant.setDesc(aData.getString("desc"));
                            merchant.setCity(aData.getString("city"));
                            merchant.setImage(aData.getString("image"));
                            merchant.setUserId(aData.getString("userId"));
                            merchant.setVipdiscount(aData.getString("vipDiscount"));
                            merchant.setLastTopic(aData.getString("lastTopic"));
                            merchant.setNewGoods(aData.getString("newGoods"));
                            merchant.setLevel(aData.getInt("level"));
                            mDatalist.add(merchant);
                        }
                    } else {//失败
                        TipUtil.showToast(message, MerchantActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service), MerchantActivity.this, 1);
                }
                TipUtil.closeProgressDialog();
                Message msg = new Message();
                msg.what = 1;
                mHandler.sendMessage(msg);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), MerchantActivity.this, 1);
                TipUtil.closeProgressDialog();
                isDataChangeOk=true;
                iCurrPage--;
                Message msg = new Message();
                msg.what = 1;
                mHandler.sendMessage(msg);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("paging.currentPage",String.valueOf(iCurrPage));//当前页码
                map.put("paging.pageSize", Constant.PAGESIZE+" ");//查询条数
                map.put("shopName",aQueryText.getText().toString().trim());//商店名称
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);

    }
    @Override
    protected void onDestroy() {
        mQueue.cancelAll(this);
        super.onDestroy();
    }

    private void getRecordsTo(){
//        TipUtil.openProgressDialog(Constant.APPLICATION_NAME, getResources().getString(R.string.please_waitting), MerchantActivity.this);
        isDataChangeOk=false;
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.GetMerchantList, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    isDataChangeOk=true;
                    TipUtil.closeProgressDialog();
                    TipUtil.log("查询商家列表", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功
                        JSONArray data = res.getJSONArray("data");
                        for (int i = 0; i < data.length(); i++) {
                            JSONObject aData = (JSONObject) data.get(i);
                            Merchant merchant = new Merchant();
                            merchant.setShopId(aData.getString("shopId"));
                            merchant.setShopName(aData.getString("shopName"));
//                            Log.e("name",aData.getString("shopName"));
                            merchant.setLogo(aData.getString("logo"));
                            merchant.setDiscount(aData.getString("discount"));
                            merchant.setAddress(aData.getString("address"));
                            merchant.setTelephone(aData.getString("telephone"));
                            merchant.setTelephoneOne(aData.getString("telephoneOne"));
                            merchant.setMobile(aData.getString("mobile"));
                            merchant.setDesc(aData.getString("desc"));
                            merchant.setCity(aData.getString("city"));
                            merchant.setImage(aData.getString("image"));
                            merchant.setUserId(aData.getString("userId"));
                            merchant.setVipdiscount(aData.getString("vipDiscount"));
                            merchant.setLastTopic(aData.getString("lastTopic"));
                            merchant.setNewGoods(aData.getString("newGoods"));
                            merchant.setLevel(aData.getInt("level"));
                            mDatalist.add(merchant);
                        }
                    } else {//失败
                        TipUtil.showToast(message, MerchantActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service), MerchantActivity.this, 1);
                }
                TipUtil.closeProgressDialog();
                Message msg = new Message();
                msg.what = 1;
                mHandler.sendMessage(msg);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), MerchantActivity.this, 1);
                TipUtil.closeProgressDialog();
                isDataChangeOk=true;
                iCurrPage--;
                Message msg = new Message();
                msg.what = 1;
                mHandler.sendMessage(msg);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("paging.currentPage",String.valueOf(iCurrPage));//当前页码
                map.put("paging.pageSize", Constant.PAGESIZE+" ");//查询条数
                Log.e("aa",aQueryText.getText().toString().trim());
                String shopName=aQueryText.getText().toString().trim();
                map.put("shopName",shopName);//商店名称
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);

    }
}
